package com.kaibes.web.security.net;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.stereotype.Component;

import com.kaibes.web.security.core.CheckAuthority;

@Component
public class CheckAuthorityNet implements CheckAuthority {

    @Autowired
    private AuthorityClient authorityClient;
    
	@Override
	public boolean hasAuthority(HttpServletRequest request, Authentication authentication, String authority) {
	    Integer roleId = (Integer) request.getAttribute("roleId");
		return authorityClient.has(roleId, authority).isValue();
	}

}
